<!--
 * @Author: wangming
 * @Date: 2021-04-15 15:38:32
 * @LastEditors: wangming
 * @LastEditTime: 2021-11-02 17:00:27
 * @Description: 数据字段
-->
<template>
  <div>
    <el-form-item :label="label">
      <el-input
        readonly
        @click.native="openModule"
        :value="value.__config.showlabel"
        placeholder="请选择"
      ></el-input>
    </el-form-item>
    <el-dialog :visible="showVisible" center :show-close="false" width="660px">
      <div class="b g3 f16 tl" slot="title">
        <div class="ks-row-between pl15 pr15">
          <span>显示字段</span>
          <span
            class="el-icon-close g9 f26 poi"
            @click="showVisible = false"
          ></span>
        </div>
      </div>
      <div class="pl30 pr30">
        <LabelExpression :fields="fields" v-model="nodelabel"></LabelExpression>
      </div>
      <div slot="footer" class="tr">
        <el-button @click="showVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import basicmixins from "./basicmixins";
import { getHmentitymodelList } from '@/apis/paas/HmEntityModelController.js'
import LabelExpression from "@/components/LabelExpression/index";
import { mapGetters } from "vuex";
export default {
  components: { LabelExpression },
  mixins: [basicmixins],
  computed: { ...mapGetters(["getFormId"]) },
  data() {
    return {
      showVisible: false,
      fields: [],
      nodelabel: "",
      modelKey: "",
      label: this.value.tagName === "hlQrcode" ? "二维码内容" : "节点显示标签",
    };
  },
  methods: {
    openModule() {
      this.getList();
    },
    submit() {
      this.value.__config.showlabel = this.nodelabel;
      this.showVisible = false;
    },
    async getList() {
      if (this.value.tagName === "hlQrcode") {
        this.modelKey = this.getFormId;
      } else {
        this.modelKey = this.value.__config.modelCode;
      }
      if (!this.modelKey) {
        this.$message.info("请绑定业务模型");
        return;
      }
      let fields = await getHmentitymodelList({
        modelKey: this.modelKey,
        activated: true,
      });
      this.fields = fields.map(({ name, code }) => ({
        label: name,
        value: code,
      }));
      this.showVisible = true;
      this.nodelabel = this.value.__config.showlabel;
    },
  },
};
</script>

